﻿
#region 文件信息
/*----------------------------------------------------------------
// 
// 文件名称：	
// 文件功能描述：	
// 设计要求：	
//
// 文 件 名：    test
// 创建者：      杨程
// 创建日期：	    2023/2/6 17:16:44

//----------------------------------------------------------------*/
#endregion


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Vampirewal.Core.Attributes;
using Vampirewal.Core.SimpleMVVM;

namespace test.ViewModel.SourceGenerator;

[GeneratorAopProxy]
public partial class TestViewModel:NotifyBase
{
    public TestViewModel()
    {
        string result = haha_Proxy("11");

        //ExcuteProxy("haha","12345");
    }

    private object ExcuteProxy2(string MethodName,params object[] args)
    {
        object? result = null;

        var method = this.GetType().GetMethod(MethodName);
        object[]? attrs = method.GetCustomAttributes(true);

        foreach (var item in attrs)
        {
            if (item is AopBaseAttribute aop)
            {
                AopMethod aopMethod = new AopMethod(this, method, args);
                Exception? ex = null;
                try
                {
                    if (aop.Location == InvokeLocation.Before)
                    {
                        aop.ExcuteBefore();
                    }

                    if (aop.Location == InvokeLocation.Both)
                    {
                        aop.ExcuteMiddle(aopMethod);
                    }
                }
                catch (Exception exx)
                {
                    ex=exx;
                }

                if (aopMethod.ReturnValue is Task)
                {
                    (aopMethod.ReturnValue as Task).ContinueWith((Task t) =>
                    {
                        aop.ExcuteAfter(aopMethod, t.Exception);
                    });
                }
                else
                {
                    aop.ExcuteAfter(aopMethod, ex);
                }

                result = aopMethod.ReturnValue;
            }
        }

        return result;
    }

    public RelayCommand aaa => new RelayCommand(() =>
    {
       
    });

    /// <summary>
    /// haha
    /// </summary>
    /// <param name="aa"></param>
    [RelayCommand]
    private void Start( int aa)
    {
        
    }

    [RelayCommand]
    public void Stop(bool IsOK)
    {
        MainViewModelDTO DTO = new MainViewModelDTO();

        var aaa= DTO.FromDTO();
    }
    /// <summary>
    /// 傻屌
    /// </summary>
    [RelayCommand]
    public void ShaDiao()
    {
        testDTO testDTO = new testDTO()
        {
            Name = "",
            Age = 11
        };

        var aaa= testDTO.FromDTO();
        int asd= aaa.Haha;
    }

    [testAOP(Location = InvokeLocation.Before)]
    public void testAOP(string a,int b,decimal c)
    {

    }

    //[testAOP(Location = InvokeLocation.Before)]
    [test2AOP(Location = InvokeLocation.Both)]
    public string haha(string asd)
    {

        return asd + "123";
    }

    [testAOP(Location = InvokeLocation.Before)]
    public int haha2(int a)
    {
        return 123;
    }
    
    
    private int _age;
    /// <summary>
    /// 123
    /// <para>321</para>
    /// </summary>
    public int Age
    {
        get
        {
            return _age;
        }
        set
        {
            _age = value;
            DoNotify();
        }
    }

}

/// <summary>
/// 
/// </summary>
[GeneratorDTO]
public partial class test:NotifyBase
{
    public test()
    {
        OnHahaChanging = new Action<int, int>((oldvalue, newvalue) =>
        {

        });

        OnHahaChanged = new Action<int>(value =>
        {

        });

        OnAmountChanging = new Action<decimal, decimal>((value1, value2) =>
        {

        });

        
    }

    
    public string Name { get; set; }
    
    public int Age { get; set; }

    /// <summary>
    /// 哈哈
    /// </summary>
    [DoNotifyProperty]
    private int haha;
    [DoNotifyProperty]
    private decimal amount;

}



[GeneratorDTO]
public partial class test123 
{
    public bool IsUgly { get; set; }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public string aaa()
    {
        return "";
    }
}

[GeneratorDTO]
public partial class MainViewModel
{
    
    public int Id { get; set; }

    public string Name { get; set; }
    
    public decimal Amount { get; set; }
}

